package com.hrh.selectsystem.config;

import com.hrh.selectsystem.aop.MyJwtInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author hrh
 * JWT拦截配置
 */
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
        registry.addInterceptor(jwtInterceptor())
                //拦截所有请求，通过判断token来决定是否需要登陆
                .addPathPatterns("/**")
                //放行请求
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/student/login")
                .excludePathPatterns("/mentor/login");
    }

    @Bean
    public MyJwtInterceptor jwtInterceptor(){
        return new MyJwtInterceptor();
    }
}